/****************************************************************************
 * Copyright (C) 2009-2010 SciTouch LLC
 * 
 * This file is part of Indigo toolkit.
 * 
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 3 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 ***************************************************************************/

#ifndef __molfile_saver__
#define __molfile_saver__

#include "base_cpp/array.h"

class Molecule;
class Output;
class GraphHighlighting;

class MolfileSaver
{
public:

   MolfileSaver (Output &output);

   void saveMolecule       (const Molecule &mol);
   void saveQueryMolecule  (const Molecule &mol);
   void saveCtab3000       (const Molecule &mol);
   void saveQueryCtab3000  (const Molecule &mol);

   bool v2000;

   const GraphHighlighting *highlighting;

   //optional parameters for reaction
   const Array<int>* reactionAtomMapping;
   const Array<int>* reactionAtomInversion;
   const Array<int>* reactionAtomExactChange;
   const Array<int>* reactionBondReactingCenter;

   DEF_ERROR("molfile saver");
protected:
   void _writeHeader (Output &output, const Molecule &mol);
   void _writeCtabHeader (Output &output);
   void _writeAtomLabel (Output &output, int label);
   void _writeMultiString (Output &output, const char *string, int len);
   void _writeCtab (Output &output, const Molecule &mol, bool is_query, bool is_rgroup = false);
   void _writeOccurenceRanges (Output &out, const Array<int> &occurences);
   void _writeRGroup (Output &output, const Molecule &query, int rg_idx);
   void _writeCtabHeader2000 (Output &output, const Molecule &mol);
   void _writeCtab2000 (Output &output, const Molecule &mol, bool is_query);
   void _writeRGroupIndices2000 (Output &output, const Molecule &query);
   void _printOccurenceRanges (Output &out, const Array<int> &occurences);
   void _writeAttachemtValues2000 (Output &output, const Molecule &fragment);

   Output &_output;

private:
   MolfileSaver (const MolfileSaver &); // no implicit copy
};



#endif
